<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('学员信息列表')" />
</head>
<body class="gray-bg">
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
<!--                            <li>-->
<!--                                <label>时间：</label>-->
<!--                                <input type="text" class="time-input" placeholder="请选择资源时间" name="resourceTime"/>-->
<!--                            </li>-->
<!--                            <li>-->
<!--                                <label>来源：</label>-->
<!--                                <select name="resourceType" th:with="type=${@dict.getType('crm_resource_type')}">-->
<!--                                    <option value="">所有</option>-->
<!--                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>-->
<!--                                </select>-->
<!--                            </li>-->
                            <li>
                                <label>渠道：</label>
                                <select name="resourceCode" th:with="type=${@dict.getType('crm_resource_code')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>推广：</label>
<!--                                <input type="text" name="resourceUserId"/>-->
                                <select id="resource-user" name="resourceUserId" class="form-control select2-multiple">
                                    <option value="">&#45;&#45;所有&#45;&#45;</option>
                                    <optgroup label="--推广--">
                                        <option th:each="user:${promotionList}" th:value="${user.userId}" th:text="${user.userName}"></option>
                                    </optgroup>
                                    <optgroup label="--更多--">
                                        <option th:each="user:${users}" th:value="${user.userId}" th:text="${user.userName}"></option>
                                    </optgroup>
                                    <optgroup label="--已失效用户--">
                                        <option th:each="user:${disabledUsers}" th:value="${user.userId}" th:text="${user.userName}"></option>
                                    </optgroup>
                                </select>
                            </li>
                            <li>
                                <label>评级：</label>
                                <select name="levelCode" th:with="type=${@dict.getType('crm_student_level')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>销售类型：</label>
                                <select name="salesType" th:with="type=${@dict.getType('crm_sales_type')}">
                                    <option value="">所有</option>
                                    <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                                </select>
                            </li>
                            <li>
                                <label>销售人员：</label>
<!--                                <input type="text" name="salesmanId"/>-->
                                <div class="col-sm-8">
                                    <select id="salesman" name="salesmanId" class="form-control">
                                        <option value="">&#45;&#45;所有&#45;&#45;</option>
                                        <optgroup label="--招生顾问--">
                                            <option th:each="user:${salesmanList}" th:value="${user.userId}" th:text="${user.userName}"></option>
                                        </optgroup>
                                        <optgroup label="--更多--">
                                            <option th:each="user:${users}" th:value="${user.userId}" th:text="${user.userName}"></option>
                                        </optgroup>
                                        <optgroup label="--已失效用户--">
                                            <option th:each="user:${disabledUsers}" th:value="${user.userId}" th:text="${user.userName}"></option>
                                        </optgroup>
                                    </select>
                                </div>
                            </li>
                            <li>
                                <label>跟踪状态：</label>
                                <div class="col-sm-8">
                                    <select id="followStatus" name="followStatus" class="form-control">
                                        <option value="">&#45;&#45;所有&#45;&#45;</option>
                                        <option value="0">跟踪中</option>
                                        <option value="1">未跟踪</option>
                                    </select>
                                </div>
                            </li>
                            <li>
                                <label>收藏状态：</label>
                                <div class="col-sm-8">
                                    <select id="collectStatus" name="collectStatus" class="form-control">
                                        <option value="">&#45;&#45;所有&#45;&#45;</option>
                                        <option value="0">已收藏</option>
                                        <option value="1">未收藏</option>
                                    </select>
                                </div>
                            </li>
                            <li>
                                <label>学员姓名：</label>
                                <input type="text" name="stuName"/>
                            </li>
                            <li>
                                <label>手机号：</label>
                                <input type="text" name="stuMobile"/>
                            </li>
                            <li>
                                <label>微信号：</label>
                                <input type="text" name="stuWechat"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>

            <div class="btn-group-sm" id="toolbar" role="group">
                <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="system:student:add">
                    <i class="fa fa-plus"></i> 添加
                </a>
                <a class="btn btn-primary single disabled" onclick="$.operate.edit()" shiro:hasPermission="system:student:edit">
                    <i class="fa fa-edit"></i> 修改
                </a>
                <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()" shiro:hasPermission="system:student:remove">
                    <i class="fa fa-remove"></i> 删除
                </a>
                <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="system:student:export">
                    <i class="fa fa-download"></i> 导出
                </a>
            </div>
            <div class="col-sm-12 select-table table-striped">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:student:edit')}]];
        var removeFlag = [[${@permission.hasPermi('system:student:remove')}]];
        var listFlag = [[${@permission.hasPermi('system:followup:list')}]];
        var resourceTypeDatas = [[${@dict.getType('crm_resource_type')}]];
        var resourceCodeDatas = [[${@dict.getType('crm_resource_code')}]];
        var levelCodeDatas = [[${@dict.getType('crm_student_level')}]];
        var salesTypeDatas = [[${@dict.getType('crm_sales_type')}]];
        var stuEducationCodeDatas = [[${@dict.getType('crm_edu_code')}]];
        var prefix = ctx + "system/student";

        $(function() {
            var options = {
                url: prefix + "/list",
                viewUrl: prefix + "/view/{id}",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit/{id}",
                removeUrl: prefix + "/remove",
                exportUrl: prefix + "/export",
                modalName: "学员信息",
                sortName: "resourceTime",
                sortOrder: "desc",
                pageSize: 25,
                striped: true,
                columns: [{
                    checkbox: true
                },
                {
                    field: 'id',
                    title: 'ID',
                    visible: false
                },
                {
                    field: 'resourceTime',
                    title: '时间'
                },
                {
                    field: 'resourceType',
                    title: '来源',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(resourceTypeDatas, value);
                    }
                },
                {
                    field: 'resourceCode',
                    title: '渠道',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(resourceCodeDatas, value);
                    }
                },
                // {
                //     field: 'resourceUserId',
                //     title: '来源用户'
                // },
                {
                    field: 'resourceUser',
                    title: '推广人员'
                },
                {
                    field: 'levelCode',
                    title: '学员评级',
                    sortable: true,
                    order: "desc",
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(levelCodeDatas, value);
                    }
                },
                {
                    field: 'salesType',
                    title: '销售类型',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(salesTypeDatas, value);
                    }
                },
                // {
                //     field: 'salesmanId',
                //     title: '销售人员'
                // },
                {
                    field: 'salesman',
                    title: '销售人员'
                },
                {
                    field: 'stuName',
                    title: '姓名'
                },
                {
                    field: 'stuMobile',
                    title: '手机号'
                },
                {
                    field: 'stuPhone',
                    title: '固定电话',
                    visible: false
                },
                {
                    field: 'stuWechat',
                    title: '微信号'
                },
                {
                    field: 'stuWechatName',
                    title: '微信名',
                    visible: false
                },
                {
                    field: 'stuQq',
                    title: 'QQ号',
                    visible: false
                },
                {
                    field: 'stuOtherContact',
                    title: '其他联系方式',
                    visible: false
                },
                {
                    field: 'stuProvince',
                    title: '省份'
                },
                {
                    field: 'stuCity',
                    title: '城市'
                },
                {
                    field: 'stuEducationCode',
                    title: '学历',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(stuEducationCodeDatas, value);
                    }
                },
                {
                    field: 'stuDamand',
                    title: '需求',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value, 20, "open");
                    }
                },
                {
                    field: 'note',
                    title: '备注',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value, 10, "open");
                    }
                },
                {
                    visible: editFlag == 'hidden' ? false : true,
                    title: '跟踪状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },
                {
                    visible: editFlag == 'hidden' ? false : true,
                    title: '收藏状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return collectStatusTools(row);
                    }
                },
                {
                    field: 'followTime',
                    title: '最后跟进时间'
                },
                {
                    field: 'remark',
                    title: '说明（内部）',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value, 10, "open");
                    }
                },
                {
                    title: '操作',
                    align: 'center',
                    // width: 190,
                    widthUnit: 'px',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-warning btn-xs ' + listFlag + '" href="javascript:void(0)" onclick="$.operate.view(\'' + row.id + '\')"><i class="fa fa-search"></i>详情</a> ');
                        // actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        var more = [];
                        more.push("<a class='btn btn-success btn-xs " + listFlag + "' href='javascript:void(0)' onclick='followup(" + row.id + ")'><i class='fa fa-list-ul'></i>跟进记录</a> ");
                        more.push("<a class='btn btn-danger btn-xs " + removeFlag + "' href='javascript:void(0)' onclick='$.operate.remove(" + row.id + ")'><i class='fa remove'></i>删除</a> ");
                        more.push("<a class='btn btn-success btn-xs " + editFlag + "' href='javascript:void(0)' onclick='$.operate.edit(" + row.id + ")'><i class='fa fa-edit'></i>编辑</a> ");
                        actions.push('<a tabindex="0" class="btn btn-info btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="' + more.join('') + '"><i class="fa fa-chevron-circle-right"></i>更多</a>');
                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });

        /*跟进记录-详细*/
        function followup(studentId) {
            var url = prefix + '/followup/studentId/'+ studentId;
            $.modal.openTab("跟进记录", url);
        }


        /* 用户状态显示 */
        function statusTools(row) {
            if (row.followStatus == 1) {
                return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
            }
        }

        /* 停止跟踪学员 */
        function disable(id) {
            $.modal.confirm("确认要停止跟踪学员吗？", function() {
                $.operate.post(prefix + "/changeFollowStatus", { "id": id, "followStatus": 1 });
            })
        }

        /* 跟踪学员启用 */
        function enable(id) {
            $.modal.confirm("确认要开启跟踪学员吗？", function() {
                $.operate.post(prefix + "/changeFollowStatus", { "id": id, "followStatus": 0 });
            })
        }

        /* 用户状态显示 */
        function collectStatusTools(row) {
            if (row.collectStatus == 1) {
                return '<i class=\"fa fa-toggle-off text-warning fa-2x\" onclick="collect(\'' + row.id + '\')"></i> ';
            } else {
                return '<i class=\"fa fa-toggle-on text-warning fa-2x\" onclick="disCollect(\'' + row.id + '\')"></i> ';
            }
        }

        /* 收藏学员 */
        function collect(id) {
            $.modal.confirm("确认要收藏学员吗？", function() {
                $.operate.post(prefix + "/changeCollectStatus", { "id": id, "collectStatus": 0 });
            })
        }

        /* 取消学员收藏 */
        function disCollect(id) {
            $.modal.confirm("确认要取消收藏学员吗？", function() {
                $.operate.post(prefix + "/changeCollectStatus", { "id": id, "collectStatus": 1 });
            })
        }

        // /*跟进记录-详细*/
        // function followup(studentId) {
        //     var url = prefix + '/followup/' + studentId;
        //     $.modal.openTab("跟进记录", url);
        // }
    </script>
</body>
</html>